package com.huawei.appgallery.foundation.ui.framework.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Shader.TileMode;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.util.AttributeSet;
import android.widget.RatingBar;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSViewProxy;
import com.huawei.appgallery.foundation.ui.css.RenderListener;
import com.huawei.appgallery.foundation.ui.css.adapter.CSSPropertyName;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSMonoColor;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSValue;
import o.cgr;
import o.cgw;
import o.dky.a;

public class RenderRatingBar extends RatingBar implements RenderListener {
    public RenderRatingBar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    public RenderRatingBar(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    public RenderRatingBar(Context context) {
        super(context);
    }

    public boolean onRenderReady(CSSViewProxy cSSViewProxy) {
        CSSRule rule = cSSViewProxy.getRule();
        if (rule.getStyleDeclaration() != null) {
            CSSValue propertyValue = rule.getStyleDeclaration().getPropertyValue(CSSPropertyName.FONT_COLOR);
            if (propertyValue != null && (propertyValue instanceof CSSMonoColor)) {
                int color = ((CSSMonoColor) propertyValue).getColor();
                Drawable ˏ = cgw.ˏ(getResources().getDrawable(a.ॱʽ), cgr.ॱ(color, 0.3f));
                Drawable ˏ2 = cgw.ˏ(getResources().getDrawable(a.ॱʽ), color);
                setProgressDrawable(ˎ(new Bitmap[]{ˊ(ˏ), ˊ(ˏ), ˊ(ˏ2)}));
            }
        }
        return false;
    }

    private Drawable ˎ(Bitmap[] bitmapArr) {
        int i = 0;
        int[] iArr = new int[]{16908288, 16908303, 16908301};
        float[] fArr = new float[]{5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f};
        Drawable[] drawableArr = new Drawable[3];
        for (int i2 = 0; i2 < 3; i2++) {
            Drawable shapeDrawable = new ShapeDrawable(new RoundRectShape(fArr, null, null));
            shapeDrawable.getPaint().setShader(new BitmapShader(bitmapArr[i2], TileMode.REPEAT, TileMode.CLAMP));
            ClipDrawable clipDrawable = new ClipDrawable(shapeDrawable, 3, 1);
            if (i2 == 0) {
                drawableArr[i2] = shapeDrawable;
            } else {
                drawableArr[i2] = clipDrawable;
            }
        }
        Drawable layerDrawable = new LayerDrawable(drawableArr);
        while (i < 3) {
            layerDrawable.setId(i, iArr[i]);
            i++;
        }
        return layerDrawable;
    }

    private Bitmap ˊ(Drawable drawable) {
        int intrinsicWidth = drawable.getIntrinsicWidth();
        int intrinsicHeight = drawable.getIntrinsicHeight();
        Bitmap createBitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, drawable.getOpacity() != -1 ? Config.ARGB_8888 : Config.RGB_565);
        Canvas canvas = new Canvas(createBitmap);
        drawable.setBounds(0, 0, intrinsicWidth, intrinsicHeight);
        drawable.draw(canvas);
        return createBitmap;
    }
}
